// pages/wrongset/wrongset.js
var wrongtitle = [];
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hid:true,
    question: "",
    index: 0
  },
  delete: function () {
    var that=this;
    wrongtitle.splice(that.data.index,1);
    if(wrongtitle.length==0){
      that.setData({
        hid:true
      });
      wx.setStorage({
        key: 'wrongtitle',
        data: wrongtitle,
      });
      return
    }
    if(that.data.index!=0 && that.data.index==wrongtitle.length){
      that.setData({
      index : that.data.index-1
      });
    }
    that.setData({
      question: wrongtitle[that.data.index],
    })
    wx.setStorage({
      key: 'wrongtitle',
      data: wrongtitle,
    });
  },
 
  nextQuestion: function () {
    var that = this;
    if (that.data.index < wrongtitle.length - 1) {
      that.setData({
        index: that.data.index + 1,
      });
      that.setData({
        question: wrongtitle[that.data.index],
      })
    }
  },
  lastQuestion: function () {
    var that = this;
    if (that.data.index > 0) {
      that.setData({
        index: that.data.index - 1,
        question: wrongtitle[that.data.index],
      });
      that.setData({
        question: wrongtitle[that.data.index],
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // var l=["1+2=3","3+4=7","1+4=5"]
    // wx.setStorage({
    //   key: 'wrongtitle',
    //   data: l,
    // });
    wx.getStorage({
      key: 'wrongtitle',
      success: function (res) {
        wrongtitle = res.data;
        // console.log(wrongtitle);
        // console.log(wrongtitle.length);
        if(wrongtitle.length>0){
          that.setData({
            hid: false,
            question: wrongtitle[that.data.index],
          })
        }
        console.log(that.data.hid);
      },
      fail: function (res) {
        //说明没有数据
        that.setData({
          hid: true,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})